package ru.tulupov.collectionsbenchmark.util;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class CSVParser {
	private Scanner scanner;
	private static final String DELIMITER = "[;:,]";

	public CSVParser(InputStream is) {
		this.scanner = new Scanner(is);
	}

	/**
	 * Parse CSV data
	 * 
	 * @return list of values.
	 */
	public List<String[]> parse() {
		List<String[]> result = new ArrayList<String[]>();

		while (scanner.hasNextLine()) {
			String line = scanner.nextLine();
			String[] values = line.split(DELIMITER);
			result.add(values);
		}

		return result;
	}
}
